
var regWord = /^([\w\/.?&=]+)$/;
var regInt = /^(\d+)$/;

/**
 * 菜单显示名输入框获取焦点，设置输入框校验显示信息列的样式
 * 
 * @param td_id_Col 菜单显示名校验显示列
 * @param s_id_Desc 提示信息显示Span ID
 */
function displayNameFocus(td_id_Col, s_id_Desc) {
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    var infoMsg = "菜单显示名，必填，最长16个字符";
    displayInfoStyle(td_id_ColObj, s_id_DescObj, infoMsg);
}

/**
 * 用户名输入框失去焦点时的校验
 * 
 * @param i_obj 用户名输入信息框焦点
 * @param td_id_Col
 * @param s_id_Desc
 */
function displayNameBlur(i_obj, td_id_Col, s_id_Desc) {
	var chkResult = true;
	
    var displayNameV = i_obj.value;
    if(displayNameV) {
    	displayNameV = displayNameV.trim();
    	i_obj.value = displayNameV;
    }
    
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    
    var errMsg = "";
    if(displayNameV == "") {
        errMsg = "菜单显示名不能为空";
    } else if(displayNameV.length > 16 ) {
        errMsg = "菜单显示名最大长度为16个字符";
    }
    
    if(errMsg != "") {
        displayErrorStyle(td_id_ColObj, s_id_DescObj, errMsg);
        chkResult = false;
        return chkResult;
    }
    
    // 校验通过
    displayOkStyle(td_id_ColObj, s_id_DescObj);
    
    return chkResult;
}

/**
 * 菜单显示顺序 获取焦点时的校验
 * @param td_id_Col 菜单显示顺序校验显示列
 * @param s_id_Desc 提示信息显示Span ID
 */
function displayOrderFocus(td_id_Col, s_id_Desc) {
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    var infoMsg = "菜单显示顺序，必填，整数。由小到大排列。";
    displayInfoStyle(td_id_ColObj, s_id_DescObj, infoMsg);
}

/**
 * 菜单显示顺序输入框 失去焦点时的校验
 * 
 * @param i_obj 用户名输入信息框焦点
 * @param td_id_Col
 * @param s_id_Desc
 */
function displayOrderBlur(i_obj, td_id_Col, s_id_Desc) {
	var chkResult = true;
	
    var displayOrderV = i_obj.value;
    if(displayOrderV) {
    	displayOrderV = displayOrderV.trim();
    	i_obj.value = displayOrderV;
    }
    
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    
    var errMsg = "";
    if(displayOrderV == "") {
        errMsg = "菜单显示顺序不能为空";
    } else if(!regInt.test(displayOrderV)) {
        errMsg = "菜单显示顺序只能为正整数";
    }
    
    if(errMsg != "") {
        displayErrorStyle(td_id_ColObj, s_id_DescObj, errMsg);
        chkResult = false;
        return chkResult;
    }
    
    // 校验通过
    displayOkStyle(td_id_ColObj, s_id_DescObj);
    
    return chkResult;
}

/**
 * URL输入项获取焦点
 */
function urlFocus(td_id_Col, s_id_Desc) {
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    var infoMsg = "菜单URL，必填，最大长度128字符";
    displayInfoStyle(td_id_ColObj, s_id_DescObj, infoMsg);
}

/**
 * URL输入项失去焦点
 * @returns {Boolean}
 */
function urlBlur(i_obj, td_id_Col, s_id_Desc) {
	var chkResult = true;
	
    var urlV = i_obj.value;
    if(urlV) {
    	urlV = urlV.trim();
    	i_obj.value = urlV;
    }
    
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    
    var errMsg = "";
    if(urlV == "") {
        errMsg = "菜单URL不能为空";
    } else if(!regWord.test(urlV)) {
        errMsg = "菜单URL只能为字符";
    } else if(urlV.length > 128) {
    	errMsg = "菜单URL最大长度为128个字符";
    }
    
    if(errMsg != "") {
        displayErrorStyle(td_id_ColObj, s_id_DescObj, errMsg);
        chkResult = false;
        return chkResult;
    }
    
    // 校验通过
    displayOkStyle(td_id_ColObj, s_id_DescObj);
    
    return chkResult;
}

/**
 * 添加新功能菜单表单提交
 */
function addMenuFun() {
	// 校验菜单显示名
	var displayNameObj = document.getElementById("displayName");
	if(!displayNameBlur(displayNameObj, 'displayNameCol', 'displayNameDesc')) {
		return false;
	}
	
	// 校验菜单显示顺序
	var displayOrderObj = document.getElementById("displayOrder");
	if(!displayOrderBlur(displayOrderObj, 'displayOrderCol', 'displayOrderDesc')) {
		return false;
	}
	
	// 校验菜单URL
	var urlObj = document.getElementById("url");
	if(!urlBlur(urlObj, 'urlCol', 'urlDesc')) {
		return false;
	}
	
	document.getElementById("menuCfgForm").submit();
    return true;
}

